// 单链表删除节点
//单向链表和一个节点的值，从单向链表中删除等于该值的节点，
// 删除后如果链表中无节点则返回空指针。
#include <bits/stdc++.h>
using namespace std;
struct ListNode {
  int val;
  ListNode* next;
  ListNode(int v, ListNode* p = nullptr) : val(v), next(p) {}
};
//插入节点
void InsertAfter(ListNode* fa, ListNode* ch) {
  ListNode* succ = fa->next;
  fa->next = ch;
  ch->next = succ;
}
//删除节点，并返回头结点
ListNode* DeleNode(ListNode* head, int val) {
  ListNode* prev = new ListNode(-1);  //前置节点
  prev->next = head;
  head = prev;
  while (head->next) {
    if (head->next->val == val) {
      head->next = head->next->next;
      break;
    }
    head = head->next;
  }
  return prev->next;
}
int main() {
  int num = 0, val = 0;
  while (cin >> num >> val) {
    ListNode* head = new ListNode(val);
    ListNode* fath = head;
    vector<pair<int, int>> vec;
    int child, father, count = num - 1;
    while (--num) {
      cin >> child >> father;
      vec.push_back(make_pair(child, father));
    }
    //构建链表
    while (count) {
      for (int i = 0; i < vec.size(); i++) {
        //寻找父节点
        if (vec[i].second == fath->val) {
          //构造子节点
          ListNode* node = new ListNode(vec[i].first);
          //插入子节点
          InsertAfter(fath, node);
          //删除
          // vec.erase(vec.begin() + i);
          vec[i] = make_pair(-1, -1);
          count--;
        }
      }
      fath = fath->next;
    }
    //删除
    int deleval = 0;
    cin >> deleval;
    head = DeleNode(head, deleval);
    fath = head;
    //输出
    while (fath) {
      cout << fath->val << " ";
      fath = fath->next;
    }
    cout << endl;
    //销毁
    while (head) {
      fath = head->next;
      delete (head);
      head = fath;
    }
  }
  return 0;
}